package com.lz.ccjdemo;

import android.app.Activity;
import android.app.Application;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

import com.lz.ccjdemo.greendao.dao.DaoMaster;
import com.lz.ccjdemo.greendao.dao.DaoSession;
import com.lz.ccjdemo.greendao.dao.WarehouseDataDao;
import com.lz.ccjdemo.greendao.data.WarehouseData;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.internal.DaoConfig;

import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
import uk.co.chrisjenx.calligraphy.R;

public class App extends Application {

    public static App app;


    public DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        //全局字体替换
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("fonts/Roboto-ThinItalic.ttf")
                .setFontAttrId(R.attr.fontPath)
                .build());

        DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(this, "ccj.db");
        DaoMaster daoMaster = new DaoMaster(openHelper.getWritableDb());
        daoSession = daoMaster.newSession();

        initActivityLifecycleCallbacks();
    }

    private Activity curActivity;

    public Activity getCurActivity() {
        return curActivity;
    }

    private void initActivityLifecycleCallbacks() {
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {

            @Override
            public void onActivityCreated(Activity activity, Bundle bundle) {

            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {
                curActivity=activity;
            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {

            }
        });
    }

    public static App getApp() {
        if (app == null) {
            app = new App();
        }

        return app;
    }
}
